from sqlalchemy.ext.declarative import declarative_base

# 创建 Base 类
Base = declarative_base()

from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship

# 定义 User 模型，继承自 Base
class User(Base):
    __tablename__ = 'users'  # 对应数据库中的表名

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String, unique=True, nullable=False)
    email = Column(String, unique=True, index=True, nullable=False)
    hashed_password = Column(String, nullable=False)
    full_name = Column(String, nullable=True)

    # 可选：设置一个 relationship 来关联其他表（如 Post 表）
    # posts = relationship("Post", back_populates="owner")

    def __repr__(self):
        return f'<User {self.username}>'
